package prv.pursuivant.config.impl;

import java.util.Collections;
import java.util.List;

import prv.pursuivant.config.CategoryDesc;
import prv.pursuivant.config.Config;
import prv.pursuivant.config.ConfigSerializer;
import prv.pursuivant.config.ImporterDesc;
import prv.pursuivant.core.AllToons;
import prv.pursuivant.core.Toon;
import prv.pursuivant.core.impl.AllToonsImpl;

import com.google.inject.Inject;
import com.google.inject.internal.Lists;

class AchievTypeId {

	final String id;

	AchievTypeId(String id) {
		this.id = id;
	}
}

/**
 * 
 * Represents configuration of the program
 * 
 * @author Kwinto
 * @see ConfigSerializer
 * 
 */
public class ConfigImpl implements Config {

	private final CategoryDesc activeCategory;
	private final ImporterDesc importer;
	private final List<AchievTypeId> activeAchievements;
	private final List<Toon> toons;

	/**
	 * Constructor, incjectable.
	 * 
	 * @param activeCategory
	 *            Note: I still don't know if it shouldn't go to importer
	 *            description, as it is important only when importing data from
	 *            armory (or cache). Or is it not?
	 */
	@Inject
	public ConfigImpl(CategoryDesc activeCategory, ImporterDesc importer,
			List<String> activeAchievements, List<Toon> toons) {
		this.activeCategory = activeCategory;
		this.importer = importer;
		if (activeAchievements == null)
			this.activeAchievements = null;
		else {
			this.activeAchievements = Lists.newArrayList();
			for (String aId : activeAchievements)
				this.activeAchievements.add(new AchievTypeId(aId));
		}
		this.toons = toons;
	}

	/**
	 * Gets the active category
	 * 
	 * @return active category (168 for "Dungeons and Raids")
	 */
	public CategoryDesc getActiveCategory() {
		return activeCategory;
	}

	/**
	 * Gets the list of achievements user wants to have formatted output for.
	 * 
	 * @return the activeAchievements
	 */
	public List<String> getActiveAchievements() {
		if (activeAchievements == null)
			return Collections.emptyList();
		List<String> result = Lists.newArrayList();
		for (AchievTypeId id : activeAchievements) 
			result.add(id.id);
		return result;
	}

	/**
	 * Gets the list of toons.
	 * 
	 * @return the toons
	 */
	public AllToons getToons() {
		return new AllToonsImpl(this.toons);
	}

	@Override
	public ImporterDesc getImporterDesc() {
		return this.importer;
	}

}
